//
// Created by xili on 2024/8/19 21:25.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    vector<int> findMissingAndRepeatedValues(vector <vector<int>> &grid) {
        unordered_map<int, int> ump;
        int n = grid.size() * grid.size();
        for (int i = 1; i < n; i++) {
            ump[i]++;
        }
        for (auto &item: grid) {
            for (auto &it: item) {
                ump[it]--;
            }
        }
        vector<int> ans(2, 0);
        for (auto &item: ump) {
            if (item.second == 1) {
                ans[1] = item.first;
            } else if (item.second == -1) {
                ans[0] = item.first;
            }
        }
        return ans;
    }
};